package com.xiaoshuidi.cloud.module.contract.convert.bill;

import com.xiaoshuidi.cloud.framework.common.mapstruct.DateMapper;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.CompanyCustomerBillDetailResp;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.OrderDetailVo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.OrderDetaillAndOrderFeeVo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.OrderItemInfo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.orderFees.OrderFeesCreateVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.orderFees.OrderFeesVo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.ownerOrder.OwnerOrderApprovalDetailVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.ownerOrder.OwnerOrderExcelVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.ownerOrder.OwnerOrderInfoRespVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.ownerOrder.OwnerOrderRespVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.rentOrder.*;
import com.xiaoshuidi.cloud.module.contract.controller.app.contract.vo.AppRentOrderCreateReq;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.bill.OrderFeesDO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.bill.RentOrderDO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.bill.RentOrderEXDO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractHouseOwnerDO;
import com.xiaoshuidi.cloud.module.contract.enums.bill.OrderFeeFlowTypeEnum;
import com.xiaoshuidi.cloud.module.contract.enums.bill.OrderTypeEnum;
import com.xiaoshuidi.cloud.module.contract.enums.bill.OwnerOrderStatusEnum;
import com.xiaoshuidi.cloud.module.contract.service.bill.dto.RentOrderCreateDTO;
import com.xiaoshuidi.cloud.module.contract.util.bill.RemainingAmount;
import com.xiaoshuidi.cloud.module.contract.vo.OrderFeeDetailVO;
import com.xiaoshuidi.cloud.module.contract.vo.OrderFeesMeterVo;
import com.xiaoshuidi.cloud.module.contract.vo.RentOrderCreateMeterReq;
import com.xiaoshuidi.cloud.module.contract.vo.RentOrderExtVO;
import com.xiaoshuidi.cloud.module.contract.vo.RentOrderSowTicketVO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;

/**
 * 账单 Convert
 *
 * @author 合房租赁
 */
@Mapper(
        collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
public interface RentOrderConvert extends DateMapper {

    RentOrderConvert INSTANCE = Mappers.getMapper(RentOrderConvert.class);

    RentOrderDO convert(RentOrderCreateReqVO bean);

    RentOrderDO convert(RentOrderUpdateReqVO bean);

    RentOrderRespVO convert(RentOrderDO bean);

    RentOrderDO convert(OrderFeesCreateVO bean);

    List<RentOrderRespVO> convertList(List<RentOrderDO> list);

    List<RentOrderResp> convertList01(List<RentOrderEXDO> list);

    List<OrderDetaillAndOrderFeeVo> convertList03(List<RentOrderDO> list);

    PageResult<RentOrderRespVO> convertPage(PageResult<RentOrderDO> page);

    List<RentOrderExcelVO> convertList02(List<RentOrderDO> list);

    List<RentOrderDO> convert(List<RentOrderCreateReqVO> bean);

    void convert(RentOrderDO b, @MappingTarget OrderItemInfo.OrderItemInfoBuilder infoBuilder);

    List<RemainingAmount> convertRemainingList(List<OrderFeesDO> bean);

    RentOrderCreateDTO convertOrderDetail2RentOrderCreate(OrderDetailVo bean);

    RentOrderDO convert(RentOrderCreateDTO bean);

    OrderItemInfo convert(OrderFeesDO o);

    @Mappings({
            @Mapping(source = "orderType", target = "orderType", qualifiedByName = "orderTypeEnumConvert"),
            @Mapping(source = "flowType", target = "flowType", qualifiedByName = "flowTypeEnumConvert"),
            @Mapping(source = "orderStatus", target = "orderStatus", qualifiedByName = "ownerOrderStatusEnumConvert"),
    })
    OwnerOrderExcelVO ownerOrderRespVO2OwnerOrderExcelVO(OwnerOrderRespVO bean);

    @Mappings({
            @Mapping(source = "orderType", target = "orderType", qualifiedByName = "orderTypeEnumConvert"),
            @Mapping(source = "flowType", target = "flowType", qualifiedByName = "flowTypeEnumConvert"),
            @Mapping(source = "orderStatus", target = "orderStatus", qualifiedByName = "ownerOrderStatusEnumConvert"),
    })
    List<OwnerOrderExcelVO> ownerOrderRespVOs2OwnerOrderExcelVOs(List<OwnerOrderRespVO> list);


    //账单类型字段转换
    @Named("orderTypeEnumConvert")
    default String orderTypeEnumConvert(String name) {
        return OrderTypeEnum.getName(name);
    }

    //账单状态字段转换
    @Named("flowTypeEnumConvert")
    default String flowTypeEnumConvert(Integer code) {
        OrderFeeFlowTypeEnum anEnum = OrderFeeFlowTypeEnum.getEnum(code);
        return Objects.nonNull(anEnum) ? anEnum.getName() : "";
    }

    //业主账单状态字段转换
    @Named("ownerOrderStatusEnumConvert")
    default String ownerOrderStatusEnumConvert(Integer code) {
        return OwnerOrderStatusEnum.getName(code);
    }


    RentOrderDO convert(OrderDetailVo item);

    RentOrderVO convert(RentOrderCreateReq req);


    OrderItemInfo convertItem(RentOrderDO b);

    OwnerOrderInfoRespVO convert2OwnerOrderInfo(RentOrderDO bean);

    @Mapping(source = "startTime", target = "startTime", dateFormat = "yyyy-MM-dd")
    @Mapping(source = "endTime", target = "endTime", dateFormat = "yyyy-MM-dd")
    @Mapping(source = "actualPayTime", target = "actualPayTime", dateFormat = "yyyy-MM-dd HH:mm")
    CompanyCustomerBillDetailResp convert2BillDetail(RentOrderDO bean);

    RentOrderCreateReq convertAppReq(AppRentOrderCreateReq req);

    List<com.xiaoshuidi.cloud.module.contract.vo.RentOrderVO> convertList04(List<RentOrderDO> rentOrderDOList);

    RentOrderExtVO convert2(RentOrderDO rentOrderDO);

    List<OrderFeeDetailVO> convert2(List<OrderFeesDO> feeDetails);

    List<RentOrderContractVO> convertVo(List<RentOrderDO> rentOrderDOList);

    RentOrderCreateReq convertMeter(RentOrderCreateMeterReq req);

    List<RentOrderExcelVO> convertList05(List<RentOrderResp> rentOrderRespVO);

    List<RentOrderSowTicketVO> convertList06(List<RentOrderDO> selectList);

    List<OrderFeesVo> convertFeesList(List<OrderFeesMeterVo> orderFeesVo);

    void convertApprovalDetail(ContractHouseOwnerDO ownerDO, @MappingTarget OwnerOrderApprovalDetailVO builder);

    @Mapping(source = "startTime", target = "orderStartTime")
    @Mapping(source = "endTime", target = "orderEndTime")
    void convertApprovalDetail2(RentOrderDO reqVO,
                                @MappingTarget OwnerOrderApprovalDetailVO builder);

    List<RentOrderExtVO> convertPaymentOrderList(List<RentOrderDO> rentOrderDOList);

}
